package com.heima.admin.controller.v1;

import com.heima.admin.service.SensitiveService;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.common.enums.AppHttpCodeEnum;
import com.heima.model.wemedia.dtos.SensitiveDto;
import com.heima.model.wemedia.pojos.WmSensitive;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/v1/sensitive")
public class SensitiveController {

    @Autowired
    private SensitiveService sensitiveService;


    /**
     * 敏感词删除
     * @param id
     * @return
     */
    @DeleteMapping( "/del/{id}")
    public ResponseResult delSensitive(@PathVariable Integer id){
        return sensitiveService.delSensitive(id);
    }

    /**
     * 敏感词查询
     * @param dto
     * @return
     */
    @PostMapping("/list")
    public ResponseResult findAll(@RequestBody SensitiveDto dto){
        //判断前端传递的参数
        if (dto == null){
            return ResponseResult.errorResult(AppHttpCodeEnum.PARAM_INVALID);
        }
        //分页参数检查
        dto.checkParam();

        return sensitiveService.findList(dto);
    }

    /**
     * 保存敏感词
     * @param dto
     * @return
     */
    @PostMapping("/save")
    public ResponseResult save(@RequestBody WmSensitive dto){

        return sensitiveService.save(dto);
    }

    /**
     * 修改敏感词
     * @param dto
     * @return
     */
    @PostMapping("/update")
    public ResponseResult update(@RequestBody WmSensitive dto){

        return  sensitiveService.update(dto);
    }

}
